<?php
defined('_JEXEC') or die( 'Restricted access' );

jimport('joomla.application.component.model');

/**
 * @package		Joomla
 * @subpackage	Contact
 */
class AddservicesModelAddservices extends JModel
{
	var $db;
	function __construct(){
		$this->db = &JFactory::getDBO();
		parent::__construct();
	}
	
	function saveList($arrfields){
		$user 	=& JFactory::getUser();
		$db = $this->db;
		$db->setQuery("START TRANSACTION");
		$db->query();
		foreach($arrfields as $key=>$value){
			$name = $value["name"];
			$price = $value["price"];
			if($name!=""){
				$result = $this->save($name,$price,$user->id);
				if(!$result){
					break;	
				}
			}
		}
		if($result)
		{
			$db->setQuery("COMMIT");
			$result = $db->query();
		}
		else
		{
			$db->setQuery("ROLLBACK");
			$db->query();
		}	
	}
	
	function save($name, $price, $userid){
		$db =  $this->db;
		$datetime = date("YmdHis");
		$query = "INSERT INTO #__services(`name`, `price`, `userid`, `timeadded`) values('$name','$price','$userid','$datetime')";
		$db->setQuery($query);
		return $db->query();
	}
}